#define LOG_TAG "TestNativeService"
#include <utils/Log.h>

#include <utils/String8.h>
#include <utils/threads.h>
#include <binder/PermissionCache.h>

#include "TestNativeService.h"

#define MAX_LEN 1024*200

namespace android {

TestNativeService* TestNativeService::instantiate()
{
    TestNativeService* self(new TestNativeService());
    defaultServiceManager()->addService(String16("TestNativeService"), self);

    self->run("TestNativeService", PRIORITY_URGENT_DISPLAY);
    return self;
}

TestNativeService::TestNativeService(): verifyPass(-100)
{
    ALOGI("TestNativeService constructor");
}

TestNativeService::~TestNativeService()
{
    ALOGI("TestNativeService desconstructor");
}

int TestNativeService::verify()
{
    Mutex::Autolock _l(mLock);

    return verifyPass;
}

static const String16 sDump("android.permission.DUMP");
status_t TestNativeService::dump(int fd, const Vector<String16>& args)
{
    String8 result;

    if (!PermissionCache::checkCallingPermission(sDump)) {
        result.appendFormat("Permission Denial: "
                "can't dump TestNativeService from pid=%d, uid=%d\n",
                IPCThreadState::self()->getCallingPid(),
                IPCThreadState::self()->getCallingUid());
    } else {
        result.appendFormat(
                "Test Native Service Detail:\n"
                "  license = %s \n"
                "  result = %s \n"
                "  pass = %d\n",
                license,
                checkResult,
                verifyPass);
    }

    write(fd, result.string(), result.size());
    return NO_ERROR;
}

}; // namespace android
